import java.util.*;

/**
 * 
 * @author keithcasamento
 * 
 *
 */
public class Investor
{
    private String name;
    private int playerID;
    private String email;
    private double cash;
    private HashMap<String, Stock> holdings = new HashMap<String, Stock>();
    /**
     * Creates new Investor instance
     * @param String investor's name
     * @param String investor's email
     */
    Investor(String n, String em)
    {
            name = n;
            email = em;
            cash = 10000.00;
    }
	
    @Override
    public int hashCode()
    {
        return playerID;
    }

    @Override
    public boolean equals(Object o)
    {
            return (o instanceof Investor)
            && (playerID == ( (Investor)o ).playerID);
    }

    /**
     * Gets the name of the Investor
     * @return String
     */
    public String getName()
    {
        return name;
    }

    /**
     * Gets the email for the investor
     * @return String
     */
    public String getEmail()
    {
        return email;
    }

    /**
     * Gets the player's ID
     * @return int
     */
    public int getID()
    {
        return playerID;
    }

    /**
     *
     * @return double
     */
    public double getCash()
    {
        return cash;
    }

    /**
     *
     * @return List<Stock>
     */
    public HashMap<String, Stock> getHoldings()
    {
        return holdings;
    }

    /**
     * Sets the parameter name
     * @param String name of Investor
     */
    public void setName(String n)
    {
        name = n;
    }

    /**
     * Sets the Investor's ID
     * @param int Investor's ID
     */
    public void setID(int id)
    {
        playerID = id;
    }

    /**
     * Sets the Investors email
     * @param String Investor's email
     */
    public void setEmail(String em)
    {
        email = em;
    }

    /**
     *
     * @param double money added to account
     */
    public void subCash(double moneySub)
    {
        cash = cash - moneySub;
    }

    /**
     *
     * @param double money added to account
     */
    public void addCash(double moneyAdd)
    {
        cash = cash + moneyAdd;
    }

    /**
     *
     * @param Stock newly added stock
     */
    public void addHolding(Stock ticker)
    {
        holdings.put(ticker.getTicker(), ticker);
    }

    /**
     *
     * @param Stock stock to be removed
     */
    public void removeHolding(int removeShares, String ticker)
    {
            int currShares = (holdings.get(ticker)).getShares();
            if(removeShares == currShares) {
                    holdings.remove(ticker);
            }
            else if(removeShares < (holdings.get(ticker)).getShares()) {
                    int oldShares = (holdings.get(ticker)).getShares();
                    int newShares = oldShares - removeShares;
                    holdings.remove(ticker);
                    holdings.put(ticker, new Stock(newShares, ticker));
            }
            else
                    System.out.println("You do not have enough shares.");
    }

    public boolean hasHolding(Stock ticker)
    {
            return holdings.containsKey(ticker.getTicker());
    }
    
}